import { Component, OnInit, ViewChild } from '@angular/core';
import { _HttpClient, ModalHelper } from '@delon/theme';
import { STColumn, STComponent } from '@delon/abc';
import { SFSchema } from '@delon/form';
import { applyCC } from '@shared';
import { getTimeDistance } from '@delon/util';
import { addDays, format } from 'date-fns';

@Component({
  selector: 'app-system-logs',
  templateUrl: './logs.component.html',
})
export class SystemLogsComponent implements OnInit {
  url = `/cf/admin/log/page`;
  searchSchema: SFSchema = {
    properties: {
      title: {
        type: 'string',
        title: '标题',
      },
      createBy: {
        type: 'string',
        title: '创建人',
      },
      start: {
        type: 'string',
        title: '日期范围',
        format: 'date',
        ui: { widget: 'date', end: 'end' },
        default: format(addDays(new Date(), -7), 'YYYY-MM-DD'),
      },
      end: {
        type: 'string',
        default: format(new Date(), 'YYYY-MM-DD'),
      },
    },
  };
  @ViewChild('st', { static: false }) st: STComponent;
  columns: STColumn[] = applyCC([
    { title: '序号', type: 'no' },
    { title: '标题', index: 'title' },
    { title: 'uri', render: 'requestUri', index: 'requestUri', ccChecked: false, width: 150 },
    { title: '参数', render: 'params', index: 'params', ccChecked: false, width: 150 },
    { title: 'ip', index: 'remoteAddr' },
    { title: '请求方式', index: 'method' },
    { title: '客户端', index: 'serviceId', ccChecked: false },
    { title: '创建日期', index: 'createTime', width: 180 },
    { title: '创建人', index: 'createBy' },
    { title: '耗时', index: 'time' },
  ]);

  constructor(private http: _HttpClient, private modal: ModalHelper) {}

  ngOnInit() {}
}
